﻿#ifndef __REDIS_MANAGER_HEAD__
#define __REDIS_MANAGER_HEAD__

#include <memory>
#include <string>
#include <vector>
#include <unordered_map>
#include "singleton.h"
#include "redis_db_connection_pool.h"
class CRedisDbConnection;

class CRedisDbManager : public Singleton<CRedisDbManager>
{
public:
	CRedisDbManager();
	~CRedisDbManager();
public:
	using InstSetType = std::vector<std::shared_ptr<CRedisDbConnection>>;
	InstSetType &GetDbInstance(const std::string &instName);
	void	KeepAlive(int iS);
	bool    Initialize(const std::string &instName, const std::string & host, const std::string & port_or_socket, const std::string & user, const std::string & password, const std::string& database);
private:
	bool CreateDbConnectPool(const std::string &instName, const std::vector<std::string> &hosts, std::vector<unsigned> ports, const std::string &auth_database, const std::string &user, const std::string &pwd, const std::vector<std::pair<std::string, std::string>> &options);
	std::unordered_map<std::string, InstSetType> m_clients;

	//connection pool
	CRedisDbConnectionPool			m_connectionPool;
};

#endif
